import java.io.*;
import java.nio.CharBuffer;
import java.util.Arrays;

public class Demo1 {
    public static void main1(String[] args) throws IOException {
        File file = new File("./test.txt");
        System.out.println(file.getPath());
        System.out.println(file.getParent());
        System.out.println(file.getAbsolutePath());
        System.out.println(file.getCanonicalPath());
        System.out.println(file.exists());
    }

    public static void main2(String[] args) throws IOException {
        File file = new File("./test.txt");
        System.out.println(file.createNewFile());
    }

    public static void main3(String[] args) throws IOException {
        File file = new File("./test.txt");
        file.createNewFile();
        System.out.println(file.exists());
        System.out.println(file.delete());
        System.out.println(file.exists());
    }

    public static void main4(String[] args) throws IOException {
        File file = new File("./test.txt");
        file.createNewFile();
        System.out.println(file.exists());
        file.deleteOnExit();
        System.out.println(file.exists());
    }

    public static void main5(String[] args) {
        File file = new File("./text.txt/2005/0");
        file.delete();
    }

    public static void main6(String[] args) {
        File file = new File("D:/code/Java/java_study/J2024_11_2");
        String[] list = file.list();
        System.out.println(Arrays.toString(list));
        File[] list2 = file.listFiles();
        System.out.println(Arrays.toString(list2));
    }

    public static void main7(String[] args) throws FileNotFoundException {
        InputStream inputStream = new InputStream() {
            @Override
            public int read() throws IOException {
                return 0;
            }
        };

        OutputStream outputStream = new FileOutputStream("./test.txt");
    }

    public static void main8(String[] args) throws IOException {
        try(InputStream inputStream = new FileInputStream("./test.txt");) {
            int n = 0;
            while (n != -1) {
                n = inputStream.read();
                System.out.println(n);
            }
        }
    }

    public static void main9(String[] args) throws IOException {
        try(InputStream inputStream = new FileInputStream("./test.txt");) {
            byte[] b = new byte[1024];
            while(true) {
                int n = inputStream.read(b);
                if(n == -1) {
                    break;
                }
                for (int i = 0; i < n; i++) {
                    System.out.println(b[i]);
                }
            }
        }
    }

    public static void main10(String[] args) throws IOException {
        try(OutputStream outputStream = new FileOutputStream("./test.txt");) {
            outputStream.write(65);
            outputStream.write(66);
            outputStream.write(67);
        }
    }

    public static void main11(String[] args) throws IOException {
        try(OutputStream outputStream = new FileOutputStream("./test.txt");) {
            byte[] b = {97,98,99};
            outputStream.write(b);
        }
    }

    public static void main12(String[] args) throws IOException {
        try(OutputStream outputStream = new FileOutputStream("./test.txt",true);) {
            byte[] b = {97,98,99};
            outputStream.write(b);
        }
    }

    public static void main13(String[] args) throws IOException {
        try(Reader reader = new FileReader("./test.txt")) {
            while(true) {
                char[] b = new char[1];
                int n = reader.read(b);
                if(n == -1) {
                    break;
                }
                for (int i = 0; i < n; i++) {
                    System.out.println(b[i]);
                }
            }
        }
    }

    public static void main14(String[] args) throws IOException {
        try(Reader reader = new FileReader("./test.txt")) {
            char[] arr = new char[2];
            while(true) {
                int n = reader.read(arr);
                if(n == -1) {
                    break;
                }
                for (int i = 0; i < n; i++) {
                    System.out.println(arr[i]);
                }
            }
        }
    }

    public static void main15(String[] args) throws IOException {
        try(Writer writer = new FileWriter("./test.txt",true)) {
            writer.write("hello world");
        }
    }

    public static void main(String[] args) {

    }
}
